home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_all.zip / TI232.ASC < prev    next >
Text File  |  1992-08-12  |  9KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  10.   VERSION : All
  11.        OS : PC-DOS
  12.      DATE : August 1, 1986                               PAGE : 1/6
  13.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  14.  
  15.  
  16.  
  17.  
  18.   The following example routines are public domain programs that
  19.   have been uploaded to our Forum on CompuServe. As a courtesy to
  20.   our users that do not have immediate access to CompuServe,
  21.   Technical Support distributes these routines free of charge.
  22.  
  23.   However, because these routines are public domain programs, not
  24.   developed by Borland International, we are unable to provide any
  25.   technical support or assistance using these routines. If you need
  26.   assistance using these routines, or are experiencing  dif
  27.  
  28.   Turbo Pascal's Intr procedure cannot call MS-DOS interrupts 25H
  29.   and 26H because they do not leave the CPU flags on the stack.
  30.   This set of functions allows you to call those interrupts, which
  31.   are Absolute Disk Read and Absolute Disk Write, by using th
  32.  
  33.   Both functions are called with the same parameters:
  34.        Buffer: a buffer large enough to hold NumberSectors 512
  35.        byte sectors.
  36.        Drive: the drive number. 0 is A:, 1 is B:, and so on.
  37.        NumberSectors: the number of sectors to transfer.
  38.        LogicalSector: the first logical sector number to transfer.
  39.  
  40.   Be sure that the Buffer is large enough to hold 512 times
  41.   NumberSectors bytes of data. Failure to do so will surely lead
  42.   to bugs that are difficult to solve.
  43.  
  44.   The integer return value is the error code returned by MS-DOS.
  45.   "0" indicates a successful transfer, all other values are errors.
  46.   See a DOS Technical Reference Manual for translations.
  47.  
  48.   A small sample program is provided. It is a minimal disk editor
  49.   and is intended as an example only, though it provides the basis
  50.   for a complete disk editor/utility. The example is commented out
  51.   -- you must remove the line with the "(*" on it.
  52.  
  53.   USE WITH CAUTION!
  54.  
  55.   {$C-}
  56.   {  Remove  the  leading  * for better keyboard  response  in  the
  57.   example program }
  58.  
  59.   Function __ReadWriteSectors(Var Buffer;
  60.                  Drive, NumberSectors, LogicalSector: Integer;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  76.   VERSION : All
  77.        OS : PC-DOS
  78.      DATE : August 1, 1986                               PAGE : 2/6
  79.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  80.  
  81.  
  82.  
  83.  
  84.                  WriteFlag: Byte): Integer;
  85.   Var Result: Integer;
  86.   Begin
  87.     Result:=0;
  88.     Inline($8A/$86/ Drive /      { MOV  AL,[BP+Drive]            }
  89.       $8B/$8E/ NumberSectors /   { MOV  CX,[BP+NumberSectors]    }
  90.       $8B/$96/ LogicalSector /   { MOV  DX,[BP+LogicalSector]    }
  91.       $55/                       { PUSH BP                       }
  92.       $1E/                       { PUSH DS                       }
  93.       $C5/$9E/ Buffer /          { LDS  BX,[BP+Buffer]           }
  94.       $80/$BE/ WriteFlag /$01/   { CMP  BYTE PTR [BP+WriteFlag],1  }
  95.       $74/$04/                   { JE   Write                      }
  96.       $CD/$25/                   { INT  25H                        }
  97.       $EB/$02/                   { JMP  WrapUp                     }
  98.       $CD/$26/                   {Write: INT 26H                   }
  99.       $5B/
  100.                           {WrapUp:POP  BX ;Dispose of flags }
  101.       $1F/                       {       POP  DS                 }
  102.       $5D/                       {       POP  BP                 }
  103.       $73/$04/                   {       JNB  Ok                 }
  104.       $89/$86/ Result            {       MOV  [BP+Result],AX     }
  105.       );                         {Ok:                            }
  106.     __ReadWriteSectors:=Result;
  107.   End;
  108.  
  109.   Function ReadSectors(Var Buffer; Drive, NumberSectors,
  110.                        LogicalSector: Integer): Integer;
  111.     Begin
  112.       ReadSectors:=
  113.      __ReadWriteSectors(Buffer,Drive,NumberSectors,
  114.                         LogicalSector,0);
  115.     End;
  116.  
  117.   Function WriteSectors(Var Buffer; Drive, NumberSectors,
  118.                         LogicalSector: Integer): Integer;
  119.     Begin
  120.       WriteSectors:=
  121.         __ReadWriteSectors(Buffer,Drive,NumberSectors,
  122.                            LogicalSector,1);
  123.     End;
  124.  
  125.   { Example program.  Delete next line to enable it: }
  126.   (*
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  142.   VERSION : All
  143.        OS : PC-DOS
  144.      DATE : August 1, 1986                               PAGE : 3/6
  145.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  146.  
  147.  
  148.  
  149.  
  150.   {$R+}
  151.  
  152.   Type
  153.     Str=String[4];
  154.  
  155.   Function Int2Hex2(B: Byte): Str;
  156.     Const H: Array [0..15] Of Char='0123456789ABCDEF';
  157.     Begin
  158.       Int2Hex2:=H[B Shr 4]+H[B And 15];
  159.     End;
  160.  
  161.   Function Int2Hex4(I: Integer): Str;
  162.     Const H: Array [0..15] Of Char='0123456789ABCDEF';
  163.     Begin
  164.       Int2Hex4:=H[I Shr 12]+H[(I Shr 8) And 15]+
  165.                 H[(I Shr 4) And 15]+H[I And 15];
  166.     End;
  167.  
  168.   Function Hex2Int1(C: Char): Byte;
  169.     Begin
  170.       Case Upcase(C) Of
  171.         '0'..'9': Hex2Int1:=Ord(C) And 15;
  172.         'A'..'F': Hex2Int1:=Ord(C) And 15+9;
  173.         Else Hex2Int1:=0;
  174.        End;
  175.     End;
  176.  
  177.   Function Hex2Int4(S: Str; Default: Integer): Integer;
  178.     Var I: Integer;
  179.     Begin
  180.       If S='' Then Hex2Int4:=Default
  181.       Else
  182.        Begin
  183.         I:=0;
  184.         While S<>'' Do
  185.          Begin
  186.           I:=I Shl 4 + Hex2Int1(S[1]);
  187.           Delete(S,1,1);
  188.          End;
  189.         Hex2Int4:=I;
  190.        End;
  191.     End;
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  208.   VERSION : All
  209.        OS : PC-DOS
  210.      DATE : August 1, 1986                               PAGE : 4/6
  211.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  212.  
  213.  
  214.  
  215.  
  216.   Procedure ShowSector(Var S);
  217.     Var Buffer: Array [0..31,0..15] Of Byte Absolute S;
  218.         I,J: Integer;
  219.         B: Byte;
  220.     Begin
  221.       For I:=0 To 31 Do
  222.        Begin
  223.         Write(Int2Hex4(I Shl 4),' |  ');
  224.         For J:=0 To 15 Do
  225.          Begin
  226.           Write(Int2Hex2(Buffer[I,J]),' ');
  227.           If J And 3=3 Then Write(' ');
  228.          End;
  229.         Write('| ');
  230.         For J:=0 To 15 Do
  231.          Begin
  232.           B:=Buffer[I,J];
  233.           If B<127 Then NormVideo
  234.           Else LowVideo;
  235.           B:=B And $7F;
  236.           If B<32 Then B:=Ord('.');
  237.           Write(Chr(B));
  238.          End;
  239.         NormVideo;
  240.         WriteLn;
  241.        End;
  242.     End;
  243.  
  244.   Var
  245.     Buffer: Array [0..511] Of Byte;
  246.     DR,LS,Result,C: Integer;
  247.     W: Char;
  248.     V: Str;
  249.     Changed: Boolean;
  250.  
  251.   Begin
  252.     FillChar(Buffer,SizeOf(Buffer),'z');
  253.     Repeat
  254.       DR:=-1;
  255.       Write('Enter the drive # to read (CR to end): ');
  256.       ReadLn(DR);
  257.       If DR In [0..25] Then
  258.        Begin
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  274.   VERSION : All
  275.        OS : PC-DOS
  276.      DATE : August 1, 1986                               PAGE : 5/6
  277.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  278.  
  279.  
  280.  
  281.  
  282.         Write('Enter the logical sector # to read: ');
  283.         ReadLn(LS);
  284.         Result:=ReadSectors(Buffer,DR,1,LS);
  285.         WriteLn('Result code = ',Result);
  286.         Changed:=False;
  287.         Repeat
  288.           ShowSector(Buffer);
  289.           Write('Enter the number of the byte to change ');
  290.           Write(' (0-1FF, CR to end): ');
  291.           ReadLn(V);
  292.           C:=Hex2Int4(V,-1);
  293.           If (C>0) And (C<512) Then
  294.            Begin
  295.             Write('Enter new value [',Int2Hex2(Buffer[C]),']: ');
  296.             ReadLn(V);
  297.             If Length(V)>1 Then
  298.               If V[1] In ['''','"'] Then Buffer[C]:=Ord(V[2])
  299.               Else Buffer[C]:=Hex2Int4(V,Buffer[C])
  300.             Else Buffer[C]:=Hex2Int4(V,Buffer[C]);
  301.             Changed:=True;
  302.            End
  303.           Else C:=-1;
  304.         Until C=-1;
  305.  
  306.         If Changed Then
  307.          Begin
  308.           Write('Write changes back to drive ',DR,',');
  309.           Write ('logical sector #',LS,' (Y/N)? ');
  310.           ReadLn(W);
  311.           If Upcase(W)='Y' Then
  312.            Begin
  313.             Result:=WriteSectors(Buffer,DR,1,LS);
  314.             WriteLn('Result code = ',Result);
  315.            End;
  316.          End;
  317.        End
  318.       Else DR:=-1;
  319.     Until DR=-1;
  320.   End.
  321.   (**)
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  340.   VERSION : All
  341.        OS : PC-DOS
  342.      DATE : August 1, 1986                               PAGE : 6/6
  343.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  344.  
  345.  
  346.  
  347.  
  348.   DISCLAIMER: You have the right to use this technical information
  349.   subject to the terms of the No-Nonsense License Statement that
  350.   you received with the Borland product to which this information
  351.   pertains.
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.